package com.house.wym.controller;



import com.house.wym.entity.House;
import com.house.wym.service.IHouserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class HomePageController {
	
	@Autowired
	private IHouserService service;

	
	@RequestMapping("/toIndexPage")
	public String toIndexPage(HttpServletRequest request) {
		List<House> findHomeInfo = service.findHomeInfo();
		request.getSession().setAttribute("House", findHomeInfo);
		return "index";
	}
	
	@RequestMapping("/findHouseByLike")
	public String findHouseByLike(HttpServletRequest request,String keywords) {
		List<House> findHomeInfo = service.findHouseByLike(keywords);
		request.getSession().removeAttribute("House");
		request.getSession().setAttribute("House", findHomeInfo);
		return "index";
	}
	
//	@RequestMapping("/findHousrOrderByAsc")
//	public String findHousrOrderByAsc(HttpServletRequest request) {
//		List<House> findHomeInfo = service.findHouseOrderByAsc();
//		request.getSession().removeAttribute("House");
//		request.getSession().setAttribute("House", findHomeInfo);
//		return "index";
//	}
//
//	@RequestMapping("/findHousrOrderByDesc")
//	public String findHousrOrderByDesc(HttpServletRequest request) {
//		List<House> findHomeInfo = service.findHouseOrderByDesc();
//		request.getSession().removeAttribute("House");
//		request.getSession().setAttribute("House", findHomeInfo);
//		return "index";
//	}

	@RequestMapping("/findHouseByType")
	public String findHouseByType(String type, HttpServletRequest request) {
		List<House> findHomeInfo = service.findHouseByType(type);
		request.getSession().removeAttribute("House");
		request.getSession().setAttribute("House", findHomeInfo);
		return "index";
	}
}
